/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021.
 * Description: By using preload which directly load ko before starting the
 * init process. It's useful to make kernel smaller, Strip modules out of the
 * kernel, Support a log of boards to common mirror. Doesn't need switch_root.
 * Author: xiaowei
 * Create: 2021-08-31
 */

#ifndef RTOS_KO_PRELOAD_H
#define RTOS_KO_PRELOAD_H

#define KO_PRELOAD_MAGIC	0xfeed4b4f
#define KO_CRC32_INIT		0xFFFFFFFF
/* from include/linux/module.h: max_len = MODULE_NAME_LEN + strlen("\.ko") + 1('\0') */
#define KO_NAME_LEN		60U
#define KO_ARGS_LEN		128U
#define KO_NUM_MAX		100U

struct ko_magic_hdr {
	unsigned int magic;
	unsigned int crc;
	unsigned int num;
	unsigned int size;
	unsigned int vsize;
};

struct ko_info_hdr {
	char name[KO_NAME_LEN];
	char args[KO_ARGS_LEN];
	unsigned int offset;
	unsigned int size;
};

/*
 *                       |______20byte____|____page_align_____|______________________|
 *                       |                |                   |                      |
 *  	packer.lzma      |  ko_magic_hdr  | ko_info_hdr1.2... | ko_file1,ko_file2... |
 *                       |________________|___________________|______________________|
 *
 * */

#define KO_INFO_SIZE    (sizeof(struct ko_info_hdr))
int ko_preload_load_module(char *name, void *addr, unsigned int size, const char *args);

#endif /* RTOS_KO_PRELOAD_H */
